{% extends "charity/layout.html" %}

{% block charity_content %}
<div class="applications-content">
    <div class="section-header">
        <h1>Volunteer Applications</h1>
    </div>

    <div class="section">
        <div class="applications-list">
            {% if applications %}
                {% for application in applications %}
                <div class="application-item">
                    <div class="volunteer-info">
                        <h3>{{ application.volunteer_name }}</h3>
                        <p class="activity-title">Activity: {{ application.activity_title }}</p>
                        <p class="apply-time">Applied: {{ application.created_at.strftime('%Y-%m-%d %H:%M') }}</p>
                    </div>
                    <div class="application-actions">
                        <button class="btn btn-success" onclick="updateApplication({{ application.id }}, 'approved')">Approve</button>
                        <button class="btn btn-danger" onclick="updateApplication({{ application.id }}, 'rejected')">Reject</button>
                    </div>
                </div>
                {% endfor %}
            {% else %}
                <div class="empty-state">
                    <i class="fas fa-inbox"></i>
                    <p>No pending volunteer applications</p>
                </div>
            {% endif %}
        </div>
    </div>
</div>

<style>
.applications-content {
    padding: 2rem;
}

.applications-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.application-item {
    background: white;
    padding: 1.5rem;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.volunteer-info h3 {
    margin: 0 0 0.5rem 0;
    color: #2c3e50;
    font-size: 1.1rem;
}

.activity-title {
    color: #34495e;
    margin-bottom: 0.25rem;
}

.apply-time {
    color: #7f8c8d;
    font-size: 0.9rem;
}

.application-actions {
    display: flex;
    gap: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.3s ease;
}

.btn-success {
    background-color: #2ecc71;
    color: white;
}

.btn-success:hover {
    background-color: #27ae60;
}

.btn-danger {
    background-color: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background-color: #c0392b;
}

.empty-state {
    text-align: center;
    padding: 3rem;
    color: #7f8c8d;
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

.empty-state p {
    font-size: 1.1rem;
}
</style>

<script>
function updateApplication(applicationId, status) {
    if (confirm('Are you sure you want to ' + (status === 'approved' ? 'approve' : 'reject') + ' this application?')) {
        fetch(`/api/applications/${applicationId}/status`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: JSON.stringify({ status: status })
        })
        .then(response => response.json())
        .then(data => {
            if (data.success) {
                location.reload();
            } else {
                alert('Operation failed: ' + data.message);
            }
        })
        .catch(error => {
            console.error('Error:', error);
            alert('An error occurred. Please try again later.');
        });
    }
}
</script>
{% endblock %} 